//
//  WBTitleButton.swift
//  Weibo
//
//  Created by apple on 2016/12/10.
//  Copyright © 2016年 yanjun. All rights reserved.
//

import UIKit

class WBTitleButton: UIButton {

    
    // 重载构造函数
    
    
     init(title: String?) {
        
        super.init(frame: CGRect())
        
        if title == nil {
            setTitle("首页", for: .normal)
        }else{
            setTitle(title! + " ", for: .normal)
            
            setImage(UIImage(named:"navigationbar_arrow_down"), for: UIControlState.normal)
            setImage(UIImage(named:"navigationbar_arrow_up"), for: UIControlState.selected)

            
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray, for: .normal)
        
        
        sizeToFit()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
        guard let titleL = titleLabel ,let imageV = imageView else {
            return
        }
        
        titleL.frame = titleL.frame.offsetBy(dx: -imageV.bounds.width, dy: 0)

        imageV.frame = imageV.frame.offsetBy(dx: titleL.bounds.width, dy: 0)
        
        
        
    }
    

}
